package com.sun.showcase.biz.testcase.excel;

import java.util.Iterator;
import java.util.List;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;

import com.sun.showcase.client.testcase.query.CaseLibraryQuery;
import com.sun.showcase.utils.DateUtils;
import com.sun.showcase.excel.AbstractExcelExportTemplate;
import com.sun.showcase.utils.StringConstant;

public class CaseLibraryTemplate extends AbstractExcelExportTemplate<List<CaseLibraryQuery>> {

	@Override
	public String[] getSheetNames() {
		return new String[]{"用例库"};
	}

	@Override
	public String[][] getTitles() {
		return new String[][]{{"所属项目","所属项目ID","所属模块","所属模块ID","用例标题","前提条件"
			,"用例步骤","预期结果","优先级","用例类型","创建人","创建时间"
			,"修改人","修改时间"
		}};
	}

	@Override
	protected void buildBody(int sheetIndex) {
		List<CaseLibraryQuery> list = this.parameters;	
		Sheet sheet = getSheet(sheetIndex);
		
		CaseLibraryQuery query = null;
		
		int startIndex = this.getBodyStartIndex(sheetIndex),
				i=0,
				index=0;
		
		for(Iterator<CaseLibraryQuery> it = list.iterator();it.hasNext();){
			
			Row row = sheet.createRow(i+startIndex);
			row.setHeight((short)300);
			
			index = 0;
			i=i+1;
			
		    query = it.next();
		    
		    createStyledCell(row,index++,query.getLibraryName());
		    createStyledCell(row,index++,query.getLibraryCode().intValue());
		    createStyledCell(row,index++,query.getModuleName());
		    createStyledCell(row,index++,query.getModuleCode().intValue());
		    createStyledCell(row,index++,query.getTitle());
		    createStyledCell(row,index++,query.getPrerequisite());
		    createStyledCell(row,index++,query.getCaseSteps());
		    createStyledCell(row,index++,query.getExpectedResult());
		    createStyledCell(row,index++,query.getLevel());
		    createStyledCell(row,index++,query.getType());
		    createStyledCell(row,index++,query.getCreateByName());
		    createStyledCell(row,index++,query.getCreateDate()==null?StringConstant.EMPTY:DateUtils.format(DateUtils.format3, query.getCreateDate()));
		    createStyledCell(row,index++,query.getModifiedByName());
		    createStyledCell(row,index++,query.getModifiedDate()==null?StringConstant.EMPTY:DateUtils.format(DateUtils.format3, query.getModifiedDate()));
		}
		
	}

}
